package com.inphase.myfood.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.inphase.myfood.dao.base.BaseController;
import com.inphase.myfood.model.Member;
import com.inphase.myfood.service.MemberService;

@Controller
@RequestMapping("/member")
public class MemberController extends BaseController{
	/**
	 * 判断用户是否成功登录
	 * @author Tangxuebing
	 * @param userLoginName 登录名
	 * @param userPassword 登录密码
	 * @return 返回是否登录成功
	 */
	@RequestMapping("/login.do")
	@ResponseBody
	public Map<String, Object> queryUserByLoginName(
			@RequestParam(required = true, value = "username") String userLoginName,
			@RequestParam(required = true, value = "password") String userPassword) {
		Map<String, Object> map = new HashMap<String, Object>();
		String[] params = { "userLoginName" };
		Object[] objects = { userLoginName };
		List<Member> members = memberService.getObjectByParams(params, objects);
		if (members != null && members.size() != 0) {
			Member member = members.get(0);
			if (member.getUserLoginPassword().equals(userPassword)) {
				map.put("login", "true");
				map.put("userName", member.getUserName());
				map.put("userPhone", member.getUserPhone());
			}else {
				map.put("login", "false");
			}
		} else {
			map.put("login", "false");
		}
		return map;
	}
}
